<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/images/icon.png">

    <title>河海健康系统管理版</title>
    <link href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/2.0.0-beta1/css/bootstrap-select.css" rel="stylesheet">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link href="/dashboard.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css"
          rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/2.0.0-beta1/js/bootstrap-select.js"></script>
</head>

<body>

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">河海健康管理系统</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/admin">图表</a></li>
                <li><a href="#">设置</a></li>
                <li><a href="/admin/checkApply">审批申请</a></li>
                <li><a href="/logout">注销</a></li>
            </ul>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li><a href="/admin">概况</a></li>
                <li><a href="/healthAnalyse">健康分析</a></li>
                <li class="active"><a href="/labManage">实验室管理</a><span class="sr-only">(current)</span></li>
                <li><a href="/admin/checkApply">账号审批</a></li>
                <li><a href="/authority">权限管理</a></li>
                <li><a href="/admin/personal">个人中心</a></li>
                <li><a href="/QRCode">二维码生成</a></li>
            </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <h1  class="lead" style="font-size: 25px">实验室管理</h1>
            <div class="container row">
                <select class="selectpicker">
                    <option>概况</option>
                    <option>各时段实验室人数</option>
                    <option>停留时间</option>
                    <option>添加实验室</option>
                    <option>重置实验室</option>
                </select>
                <br>
                <br>
                <div class="">
                    <table class="table table-cell table-bordered table-responsive" style="background-color: #ffffff">
                        <thead>
                        <tr>
                            <th style="background-color: #ced6e0">实验室编号</th>
                            <th style="background-color: #ced6e0">总容量</th>
                            <th style="background-color: #ced6e0">剩余容量</th>
                            <th style="background-color: #ced6e0">负责人</th>
                            <th style="background-color: #ced6e0">增加容量</th>
                            <th style="background-color: #ced6e0"></th>
                            <th style="background-color: #ced6e0">更改负责人</th>
                            <th style="background-color: #ced6e0"></th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="l,index:${labs}">
                            <td th:text="${l.labid}"></td>
                            <td th:text="${l.total}"></td>
                            <td th:text="${l.capacity}"></td>
                            <td th:if="${l.id==null}">无</td>
                            <td th:if="${l.id!=null}" th:text="${l.id}"></td>
                            <form action="/labManage/addTotal" method="post">
                                <div class="row text-center">
                                    <td>
                                        <select name="n">
                                            <option>2</option>
                                            <option>4</option>
                                            <option>8</option>
                                            <option>16</option>
                                        </select>
                                    </td>
                                    <input name="labid" th:value="${l.labid}" hidden>
                                    <td><input type="submit" class="btn btn-primary" value="增加"></td>
                                </div>
                            </form>

                            <td>
                                <input type="number" th:id="${index.index+1}">
                            </td>
                            <td>
                                <input th:value="${index.index+1}" hidden>
                                <button class="btn btn-primary" onclick="change(this)">
                                    更改负责人
                                </button>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>


<script>

    function change(element) {

        var input = $(element).siblings();
        var index = $(input[0]).val();
        var id = $('#'+index).val();
        var td = $(element).parent().siblings();
        var labid = $(td[0]).text();
        $.ajax({
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            url: "/labManage/updateLabAdmin",
            data: JSON.stringify({id: id, labid: labid}),
            success: function (result) {
                if (result.responseText == "success") {
                    window.location.href = '/labManage'
                } else {
                    alert(result.responseText);
                }
            },
            error: function (result) {

                if (result.responseText == "success") {
                    window.location.href = '/labManage'
                } else {
                    alert(result.responseText);
                }

            }
        });
    }
</script>
</body>
</html>

